/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const iconv = require("iconv-lite");
const cheerio = require('cheerio');
const vm = require('vm');
const urlTool = require('url');


/**
 * 中国证券业协会
 * @type {module.Bjp2p}
 */
module.exports = class Sac extends BaseJsonAdapter{

    async reqJson(){
		const body = await this.doRequest();
        let decodeBody = iconv.decode(body, this.encoding).toString();

        let $ = cheerio.load(decodeBody);

        global.document = {
            write:function () {

            }  
        };

        let ret = []
        
        $('td[width=376].hui3b table[width=360] td').each(function (item) {
            const jsItem = $(this).find('script').html();
            if(jsItem != null){
                vm.runInThisContext(jsItem);

                ret.push({
                    title:title_all,
                    href:urlTool.resolve('http://www.sac.net.cn', url)
                })
            }
        });

        console.log(ret);
		return {data:ret};

	  }
}
